/*
O 人物
W 树，可拾取，k键砍伐变为w
w 木材，可拾取
X 炸弹，可拾取，可破坏W，S和H，但会炸掉U，X和w，八个木材和一个铁合成
U 磁铁，可拾取
H 房屋，炸弹破坏后散落w，X或U，e键进入
S 铁矿石，需要用镐子挖掘，挖掘后掉落s
s 铁矿
C 洞穴 e键进入
R 石头 破坏器或更高级工具挖掘或被炸弹炸掉落r
r 石头碎，可拾取
M 地狱传送门 e键进入
F 火焰
# 墙 不可破坏
T 地狱水晶 铁镐破坏 掉落t
t 水晶碎片
@ 遗迹，c键消耗5t献祭，召唤boss1
/ boss1的遗物，拆除5个击败boss
破坏器 消耗七个木材合成
石镐 消耗三个石头碎和两个木材合成
铁镐 消耗三个铁矿和两个木材合成
三天不睡觉会进入梦中，战胜梦魇出来
*/
#include<bits/stdc++.h>
#include<conio.h>
#include<Windows.h>
//#define int long long
#define psp putchar(' ')
#define endl putchar('\n')
using namespace std;
const int N=1e6+5;
const int M=1e3+5;
int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-'0',c=getchar();
	return x*f;
}
void print(int x){
	if(x<0)putchar('-'),x=-x;
	if(x<10){putchar(x+'0');return;}
	print(x/10);
	putchar(x%10+'0');
}
int n,m,k;
int T;
//  0
//3 + 1
//  2
int way;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
char a[M][M];
char c[M][M];
char hell[M][M];
char cave[205][105][105];
char dream[M][M];
char boss1[M][M];
int caveid[M][M];
int vis[M][M];
int hellvis[M][M];
int boss1vis[M][M];
int CaveSteel[205][105][105];
int CaveRock[205][105][105];
int test[M][M];
char Housereward[6]={'U','X','s','w','w','w'};
char Ruinsthings[6]={'#','.','.','R','R','T'};
int wood;
int boom;
int u;
int s;
int rock;
int x,y;
int crystal;
int blood=20;
int helln=1000;
int bossn1=50;
int sizes=5;
int Boomnum=50;
int Unum=40;
int Housenum=30;
int Cavenum=200;
int CaveSteelnum=100;
int CaveRocknum=900;
int Boss1Rocknum=1000;
int Firenum=50000;
int Helldoornum=200;
int Crystalnum=1000;
int Boss1swordnum=5;
int Ruinsnum=100;
int breaklevel=0;
int day;
int maxblood=20;
int daytime=200;
int nightmare;
int nosleep;
int dayornight=1;
bool fast=0;
bool usefast;
void init(){//初始化
	system("cls");
	cout<<"Wood:  "<<wood<<"    Boom:  "<<boom<<"    U:  "<<u<<"    Steel:  "<<s;
	cout<<"    Rock:  "<<rock<<"    Crystal:  "<<crystal<<"\nBlood:  "<<blood<<"/"<<maxblood<<'\n';
	cout<<"Tired:  "<<nosleep<<"/3\n";
	string openorclose=usefast?"open":"close";
	cout<<"breacklevel:  "<<breaklevel<<"    fast:  "<<openorclose<<'\n';
	string nowtime=dayornight?"day":"night";
	cout<<"Now time:"<<nowtime<<'\n';
	cout<<"Time progress:  "<<day<<"/"<<daytime<<'\n';
	cout<<"x: "<<x<<"  y: "<<y<<'\n';
}
void initdream(){//梦境初始化
	system("cls");
	cout<<"Your blood:  "<<blood<<"/"<<maxblood<<"  Nightmare's blood:  "<<nightmare<<"/3"<<'\n';
}
void initboss1(int p){//Boss1初始化
	system("cls");
	cout<<"Your blood:  "<<blood<<"/"<<maxblood<<"  Boss1's blood:  "<<p<<"/5"<<'\n';
	string openorclose=usefast?"open":"close";
	cout<<"breacklevel:  "<<breaklevel<<"    fast:  "<<openorclose<<'\n';
	cout<<"x:  "<<x<<"   y:"<<y<<'\n';
}
void move(){//移动
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(xx<1||yy<1||xx>n||yy>n){
		xx=x+dx[way];
		yy=y+dy[way];
	}
	if(xx<1||yy<1||xx>n||yy>n)return;
	if(a[xx][yy]=='W'||a[xx][yy]=='H'||a[xx][yy]=='R'||a[xx][yy]=='C'||a[xx][yy]=='M')return;
	if(a[xx][yy]=='X')boom++;
	if(a[xx][yy]=='w')wood++;
	if(a[xx][yy]=='U')u++;
	if(a[xx][yy]=='s')s++;
	if(a[xx][yy]=='r')rock++;
	day++;
	a[x][y]='.';
	x=xx,y=yy;
	a[x][y]='O';
	if(usefast){
		xx=x+dx[way];
		yy=y+dy[way];
		if(xx<1||yy<1||xx>n||yy>n){
			xx=x+dx[way];
			yy=y+dy[way];
		}
		if(xx<1||yy<1||xx>n||yy>n)return;
		if(a[xx][yy]=='W'||a[xx][yy]=='H'||a[xx][yy]=='R'||a[xx][yy]=='C'||a[xx][yy]=='M')return;
		if(a[xx][yy]=='X')boom++;
		if(a[xx][yy]=='w')wood++;
		if(a[xx][yy]=='U')u++;
		if(a[xx][yy]=='s')s++;
		if(a[xx][yy]=='r')rock++;
		a[x][y]='.';
		x=xx,y=yy;
		a[x][y]='O';
	}
}
void movehouse(){//在房屋中移动
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(xx<1||yy<1||xx>6||yy>6){
		xx=x+dx[way];
		yy=y+dy[way];
	}
	if(xx<1||yy<1||xx>6||yy>6)return;
	if(c[xx][yy]=='W'||c[xx][yy]=='H'||c[xx][yy]=='S')return;
	if(c[xx][yy]=='X')boom++;
	if(c[xx][yy]=='w')wood++;
	if(c[xx][yy]=='U')u++;
	if(c[xx][yy]=='s')s++;
	c[x][y]='.';
	x=xx,y=yy;
	c[x][y]='O';
	if(usefast){
		xx=x+dx[way];
		yy=y+dy[way];
		if(xx<1||yy<1||xx>6||yy>6){
			xx=x+dx[way];
			yy=y+dy[way];
		}
		if(xx<1||yy<1||xx>6||yy>6)return;
		if(c[xx][yy]=='W'||c[xx][yy]=='H'||c[xx][yy]=='S')return;
		if(c[xx][yy]=='X')boom++;
		if(c[xx][yy]=='w')wood++;
		if(c[xx][yy]=='U')u++;
		if(c[xx][yy]=='s')s++;
		c[x][y]='.';
		x=xx,y=yy;
		c[x][y]='O';
	}
}
void movedream(){//在梦中移动
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(xx<1||yy<1||xx>6||yy>6||dream[xx][yy]=='#')return;
	dream[x][y]='.';
	x=xx,y=yy;
	dream[x][y]='O';
}
void movecave(int id){//在洞穴中移动
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(xx<1||yy<1||xx>100||yy>100){
		xx=x+dx[way];
		yy=y+dy[way];
	}
	if(xx<1||yy<1||xx>100||yy>100)return;
	if(xx<1||yy<1||xx>100||yy>100||cave[id][xx][yy]=='S'||cave[id][xx][yy]=='R')return;
	day++;
	if(cave[id][xx][yy]=='X')boom++;
	if(cave[id][xx][yy]=='w')wood++;
	if(cave[id][xx][yy]=='U')u++;
	if(cave[id][xx][yy]=='s')s++;
	if(cave[id][xx][yy]=='r')rock++;
	cave[id][x][y]='.';
	x=xx,y=yy;
	cave[id][x][y]='O';
	if(usefast){
		xx=x+dx[way];
	    yy=y+dy[way];
		if(xx<1||yy<1||xx>100||yy>100){
			xx=x+dx[way];
			yy=y+dy[way];
		}
		if(xx<1||yy<1||xx>100||yy>100)return;
		if(xx<1||yy<1||xx>100||yy>100||cave[id][xx][yy]=='S'||cave[id][xx][yy]=='R')return;
		day++;
		if(cave[id][xx][yy]=='X')boom++;
		if(cave[id][xx][yy]=='w')wood++;
		if(cave[id][xx][yy]=='U')u++;
		if(cave[id][xx][yy]=='s')s++;
		if(cave[id][xx][yy]=='r')rock++;
		cave[id][x][y]='.';
		x=xx,y=yy;
		cave[id][x][y]='O';
	}
}
void moveboss1(){//在boss1世界中移动
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(xx<1||yy<1||xx>50||yy>50){
		xx=x+dx[way];
		yy=y+dy[way];
	}
	if(xx<1||yy<1||xx>50||yy>50)return;
	if(xx<1||yy<1||xx>bossn1||yy>bossn1||boss1[xx][yy]=='#'||boss1[xx][yy]=='/'||boss1[xx][yy]=='R')return;
	if(boss1[xx][yy]=='r')rock++;
	if(boss1[xx][yy]=='t')crystal++;
	while(boss1[xx][yy]=='F')blood--,xx+=dx[way],yy+=dy[way];
	if(boss1[xx][yy]=='T'||boss1[xx][yy]=='@'||boss1[xx][yy]=='R'||boss1[xx][yy]=='#')return;
	boss1[x][y]='.';
	x=xx,y=yy;
	boss1[x][y]='O';
	if(usefast){
		xx=x+dx[way];
		yy=y+dy[way];
		if(xx<1||yy<1||xx>50||yy>50){
			xx=x+dx[way];
			yy=y+dy[way];
		}
		if(xx<1||yy<1||xx>50||yy>50)return;
		if(xx<1||yy<1||xx>bossn1||yy>bossn1||boss1[xx][yy]=='#'||boss1[xx][yy]=='/'||boss1[xx][yy]=='R')return;
		if(boss1[xx][yy]=='r')rock++;
		if(boss1[xx][yy]=='t')crystal++;
		while(boss1[xx][yy]=='F')blood--,xx+=dx[way],yy+=dy[way];
		if(boss1[xx][yy]=='T'||boss1[xx][yy]=='@'||boss1[xx][yy]=='R'||boss1[xx][yy]=='#')return;
		boss1[x][y]='.';
		x=xx,y=yy;
		boss1[x][y]='O';
	}
}
void movehell(){//在地狱中移动
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(xx<1||yy<1||xx>helln||yy>helln){
		xx=x+dx[way];
		yy=y+dy[way];
	}
	if(xx<1||yy<1||xx>helln||yy>helln)return;
	if(xx<1||yy<1||xx>helln||yy>helln||hell[xx][yy]=='#'||hell[xx][yy]=='T'||hell[xx][yy]=='@'||hell[xx][yy]=='R')return;
	if(hell[xx][yy]=='r')rock++;
	if(hell[xx][yy]=='t')crystal++;
	while(hell[xx][yy]=='F')blood--,xx+=dx[way],yy+=dy[way];
	if(hell[xx][yy]=='T'||hell[xx][yy]=='@'||hell[xx][yy]=='R'||hell[xx][yy]=='#')return;
	hell[x][y]='.';
	x=xx,y=yy;
	hell[x][y]='O';
	if(usefast){
		xx=x+dx[way];
		yy=y+dy[way];
		if(xx<1||yy<1||xx>helln||yy>helln){
			xx=x+dx[way];
			yy=y+dy[way];
		}
		if(xx<1||yy<1||xx>helln||yy>helln)return;
		if(xx<1||yy<1||xx>helln||yy>helln||hell[xx][yy]=='#'||hell[xx][yy]=='T'||hell[xx][yy]=='@'||hell[xx][yy]=='R')return;
		if(hell[xx][yy]=='r')rock++;
		if(hell[xx][yy]=='t')crystal++;
		while(hell[xx][yy]=='F')blood--,xx+=dx[way],yy+=dy[way];
		if(hell[xx][yy]=='T'||hell[xx][yy]=='@'||hell[xx][yy]=='R'||hell[xx][yy]=='#')return;
		hell[x][y]='.';
		x=xx,y=yy;
		hell[x][y]='O';
	}
}
void Dream(){//在梦里
	for(int i=1;i<=7;i++){
		for(int j=1;j<=7;j++){
			dream[i][j]='.';
		}
	}
	for(int i=1;i<=7;i++)dream[1][i]=dream[i][1]=dream[7][i]=dream[i][7]='#';
	system("color 08");
	int X=x,Y=y;
	int WAY=way;
	x=4,y=4;
	dream[x][y]='O';
	nightmare=3;
	char zlr;//避免误按
	cin>>zlr;
	while(blood>0&&nightmare>0){
		initdream();
		for(int i=1;i<=7;i++){
			for(int j=1;j<=7;j++){
				cout<<dream[i][j];
			}
			cout<<'\n';
		}
		int testnum=5-nightmare;
		while(testnum--){
			int kx,ky;
			kx=(rand()-1)%7+1;
			ky=(rand()-1)%7+1;
			while(kx<2||ky<2||kx>6||ky>6){
				kx=(rand()-1)%7+1;
				ky=(rand()-1)%7+1;
			}
			cout<<"Nightmare:I will strike"<<kx<<','<<ky<<'\n';
			test[kx][ky]=1;
		}
		char op;
		op=getch();
		if(op=='w'){
			way=0;
			movedream();
		}
		else if(op=='d'){
			way=1;
			movedream();
		}
		else if(op=='s'){
			way=2;
			movedream();
		}
		else if(op=='a'){
			way=3;
			movedream();
		}
		if(test[x][y])blood-=4;
		initdream();
		for(int i=1;i<=7;i++){
			for(int j=1;j<=7;j++){
				cout<<dream[i][j];
			}
			cout<<'\n';
		}
		cout<<"1.Hit nightmare\n2.Restore your blood\n";
		cin>>op;
		if(op=='1')nightmare--;
		else blood=min(blood+2,20);
	}
	nosleep=0;
	dayornight=1;
	day=0;
	x=X,y=Y;
	way=WAY;
}
void BreakHouse(int xx,int yy){//破坏房子
	for(int i=xx-2;i<=xx+2;i++){
		for(int j=yy-2;j<=yy+2;j++){
			if(a[i][j]=='.'){
				int p=rand()%6;
				a[i][j]=Housereward[p];
			}
		}
	}
	a[xx][yy]='.';
}
void XBoom(){//使用炸弹
	boom--;
	for(int i=x-3;i<=x+3;i++){
		for(int j=y-3;j<=y+3;j++){
			if(a[i][j]=='w'||a[i][j]=='X'||a[i][j]=='U')a[i][j]='.';
			if(a[i][j]=='W')a[i][j]='w';
			if(a[i][j]=='H')BreakHouse(i,j);
			if(a[i][j]=='s')a[i][j]='.';
			if(a[i][j]=='S')a[i][j]='s';
			if(a[i][j]=='R')a[i][j]='r';
		}
	}
}
void XBoomcave(int id){//在洞穴使用炸弹
	boom--;
	for(int i=x-3;i<=x+3;i++){
		for(int j=y-3;j<=y+3;j++){
			if(cave[id][i][j]=='s')cave[id][i][j]='.';
			if(cave[id][i][j]=='S')cave[id][i][j]='s';
			if(cave[id][i][j]=='R')cave[id][i][j]='r';
		}
	}
}
void XBoomhell(){//在地狱使用炸弹
	boom--;
	for(int i=x-3;i<=x+3;i++){
		for(int j=y-3;j<=y+3;j++){
			if(hell[i][j]=='R')hell[i][j]='r';
			if(hell[i][j]=='#')hell[i][j]='.';
		}
	}
}
void XBoomboss1(){//在boss1世界使用炸弹
	boom--;
	for(int i=x-3;i<=x+3;i++){
		for(int j=y-3;j<=y+3;j++){
			if(boss1[i][j]=='R')boss1[i][j]='r';
			if(boss1[i][j]=='#')boss1[i][j]='.';
		}
	}
}
void Uattract(){//使用磁铁
	u--;
	for(int i=x-3;i<=x+3;i++){
		for(int j=y-3;j<=y+3;j++){
			if(a[i][j]=='w')a[i][j]='.',wood++;
			if(a[i][j]=='s')a[i][j]='.',s++;
			if(a[i][j]=='U')a[i][j]='.',u++;
			if(a[i][j]=='X')a[i][j]='.',boom++;
		}
	}
}
void Uattractcave(int id){//在洞穴使用磁铁
	u--;
	for(int i=x-3;i<=x+3;i++){
		for(int j=y-3;j<=y+3;j++){
			if(cave[id][i][j]=='s')cave[id][i][j]='.',s++;
			if(cave[id][i][j]=='U')cave[id][i][j]='.',u++;
			if(cave[id][i][j]=='X')cave[id][i][j]='.',boom++;
		}
	}
}
void Synthesis(){//合成
	cout<<"What do yo want to synthesis?\n1.X\n2.Iron Pickaxe\n3.Stone pickaxe\n4.destructor\n";
	cout<<"5.fast\n";
	char choice;
	cin>>choice;
	if(choice=='1'){
		if(wood>=8&&s){
			wood-=8;
			s--;
			boom++;
		}
	}
	else if(choice=='2'){
		if(wood>=2&&s>=3&&breaklevel<3){
			wood-=2;
			s-=3;
			breaklevel=3;
		}
	}
	else if(choice=='3'){
		if(wood>=2&&rock>=3&&breaklevel<2){
			wood-=2;
			rock-=3;
			breaklevel=2;
		}
	}
	else if(choice=='4'){
		if(wood>=7&&breaklevel<1){
			wood-=7;
			breaklevel=1;
		}
	}
	else if(choice=='5'){
		if(crystal>=3&&s>=4&&!fast){
			crystal-=3;
			s-=4;
			fast=1;
		}
	}
	system("pause");
}
void Disassemble(){//拆解
	cout<<"What do you want to sisassemble?\n1.X\n";
	char choice;
	cin>>choice;
	if(choice=='1'){
		if(boom){
			boom--;
			wood+=8;
			s++;
		}
	}
}
void Intohouse(){//在房屋里面
	for(int i=0;i<7;i++){
		for(int j=0;j<7;j++){
			c[i][j]='.';
		}
	}
	for(int i=0;i<7;i++)c[0][i]=c[i][0]=c[6][i]=c[i][6]='W';
	int X=x,Y=y;
	int WAY=way;
	x=3-dx[way]*2;
	y=3-dy[way]*2;
	c[x][y]='O';
	while(blood>0){
		init();
		for(int i=0;i<7;i++){
			for(int j=0;j<7;j++){
				cout<<c[i][j];
			}
			cout<<'\n';
		}
		char op;
		op=getch();
		if(op=='w'){
			way=0;
			movehouse();
		}
		else if(op=='d'){
			way=1;
			movehouse();
		}
		else if(op=='s'){
			way=2;
			movehouse();
		}
		else if(op=='a'){
			way=3;
			movehouse();
		}
		else if(op=='p'){
			if(dayornight)continue;
			system("color 0F");
			nosleep=0;
			sizes=5;
			day=0;
			dayornight=1;
			blood=min(maxblood,blood+2);
		}
		else if(op=='e'){
			c[x][y]='.';
			break;
		}
	}
	x=X,y=Y;
	way=WAY;
}
void Intocave(int cavesid){//在洞穴里
	system("color 08");
	int Sizes=sizes;
	sizes=3;
	int X=x,Y=y;
	int WAY=way;
	x=50,y=50;
	cave[cavesid][x][y]='O';
	while(blood>0){
		if(day==daytime){
			if(dayornight==0)nosleep++;
			dayornight=1-dayornight;
			day=0;
		}
		if(nosleep>=3){
			Dream();
			if(blood<=0)break;
			sizes=3;
		}
		init();
		for(int i=max(1,x-sizes);i<=min(100,x+sizes);i++){
			for(int j=max(1,y-sizes);j<=min(100,y+sizes);j++){
				cout<<cave[cavesid][i][j];
			}
			cout<<'\n';
		}
		char op;
		op=getch();
		if(op=='w'){
			way=0;
			movecave(cavesid);
		}
		else if(op=='d'){
			way=1;
			movecave(cavesid);
		}
		else if(op=='s'){
			way=2;
			movecave(cavesid);
		}
		else if(op=='a'){
			way=3;
			movecave(cavesid);
		}
		else if(op=='k'){
			int xx=x+dx[way];
			int yy=y+dy[way];
			if(cave[cavesid][xx][yy]=='W')cave[cavesid][xx][yy]='w',day++;
			if(cave[cavesid][xx][yy]=='S'&&breaklevel>1)cave[cavesid][xx][yy]='s',day++;
			if(cave[cavesid][xx][yy]=='R'&&breaklevel>0)cave[cavesid][xx][yy]='r',day++;
		}
		else if(op=='x'){
			XBoomcave(cavesid);
		}
		else if(op=='u'){
			Uattractcave(cavesid);
		}
		else if(op=='S'){
			Synthesis();
		}
		else if(op=='D'){
			Disassemble();
		}
		else if(op=='v'){
			if(!fast)continue;
			usefast=!usefast;
		}
		else if(op=='e'){
			cave[cavesid][x][y]='.';
			break;
		}
	}
	x=X,y=Y;
	way=WAY;
	sizes=Sizes;
}
void BOSS_soul(){//打boss1
	system("cls");
	for(int i=1;i<=bossn1;i++){
		for(int j=1;j<=bossn1;j++){
			boss1[i][j]='.';
		}
	}
	for(int i=1;i<=bossn1;i++)boss1[i][1]=boss1[1][i]=boss1[bossn1][i]=boss1[i][bossn1]='#';
	int X=x,Y=y,WAY=way;
	x=(rand()-1)%bossn1+1;
	y=(rand()-1)%bossn1+1;
	memset(boss1vis,0,sizeof(boss1vis));
	for(int i=1;i<=Boss1Rocknum;i++){
		while(boss1vis[x][y]){
			x=(rand()-1)%bossn1+1;
			y=(rand()-1)%bossn1+1;
		}
		boss1[x][y]='R';
		boss1vis[x][y]=1;
	}
	for(int i=1;i<=Boss1swordnum;i++){
		while(boss1vis[x][y]){
			x=(rand()-1)%bossn1+1;
			y=(rand()-1)%bossn1+1;
		}
		boss1[x][y]='/';
		boss1vis[x][y]=1;
	}
	int boss1swordnum=Boss1swordnum;
	while(boss1vis[x][y]){
		x=(rand()-1)%bossn1+1;
		y=(rand()-1)%bossn1+1;
	}
	boss1[x][y]='O';
	while(blood>0&&boss1swordnum>0){
		initboss1(boss1swordnum);
		for(int i=max(1,x-sizes);i<=min(bossn1,x+sizes);i++){
			for(int j=max(1,y-sizes);j<=min(bossn1,y+sizes);j++){
				cout<<boss1[i][j];
			}
			cout<<'\n';
		}
		char op;
		op=getch();
		int xx=(rand()-1)%bossn1+1;
		int yy=(rand()-1)%bossn1+1;
		boss1[xx][yy]='F';
		if(op=='w'){
			way=0;
			moveboss1();
		}
		else if(op=='d'){
			way=1;
			moveboss1();
		}
		else if(op=='s'){
			way=2;
			moveboss1();
		}
		else if(op=='a'){
			way=3;
			moveboss1();
		}
		else if(op=='x'){
			if(!boom)continue;
			XBoomboss1();
		}
		else if(op=='v'){
			if(!fast)continue;
			usefast=!usefast;
		}
		else if(op=='k'){
			int xx=x+dx[way];
			int yy=y+dy[way];
			if(boss1[xx][yy]=='R'&&breaklevel>0)boss1[xx][yy]='r';
			if(boss1[xx][yy]=='/')boss1[xx][yy]='.',boss1swordnum--;
		}
	}
	breaklevel=max(breaklevel,4);
	maxblood=25;
	boom+=3;
	u+=3;
	s+=10;
	rock+=10;
	x=X,y=Y;
	way=WAY;
}
void Intohell(){//在地狱里
	system("color 0C");
	int Sizes=sizes;
	sizes=5;
	day=0;
	int X=x,Y=y;
	int WAY=way;
	x=(rand()-1)%helln+1;
	y=(rand()-1)%helln+1;
	while(hellvis[x][y]||x<6||y<6||x>n-5||y>n-5){
		x=(rand()-1)%helln+1;
		y=(rand()-1)%helln+1;
	}
	hell[x][y]='O';
	while(blood>0){
		init();
		for(int i=max(1,x-sizes);i<=min(helln,x+sizes);i++){
			for(int j=max(1,y-sizes);j<=min(helln,y+sizes);j++){
				cout<<hell[i][j];
			}
			cout<<'\n';
		}
		char op;
		op=getch();
		if(op=='w'){
			way=0;
			movehell();
		}
		else if(op=='d'){
			way=1;
			movehell();
		}
		else if(op=='s'){
			way=2;
			movehell();
		}
		else if(op=='a'){
			way=3;
			movehell();
		}
		else if(op=='x'){
			if(!boom)continue;
			XBoomhell();
		}
		else if(op=='k'){
			int xx=x+dx[way];
			int yy=y+dy[way];
			if(hell[xx][yy]=='T'&&breaklevel>2)hell[xx][yy]='t';
			if(hell[xx][yy]=='R'&&breaklevel>0)hell[xx][yy]='r';
		}
		else if(op=='c'){
			int xx=x+dx[way];
			int yy=y+dy[way];
			if(hell[xx][yy]=='@'&&crystal>=5){
				crystal-=5;
				BOSS_soul();
			}
		}
		else if(op=='v'){
			if(!fast)continue;
			usefast=!usefast;
		}
		else if(op=='e'){
			hell[x][y]='.';
			break;
		}
	}
	x=X,y=Y;
	way=WAY;
	sizes=Sizes;
}
void E(){//按下e键
	int xx=x+dx[way];
	int yy=y+dy[way];
	if(a[xx][yy]=='H'){//进入房子
		Intohouse();
	}
	else if(a[xx][yy]=='C'){//进入洞穴
		Intocave(caveid[xx][yy]);
	}
	else if(a[xx][yy]=='M'){
		Intohell();
	}
}
signed main(){//主世界
	srand(time(0));
	n=1000;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			a[i][j]='.';
			hell[i][j]='.';
		}
	}
	x=(rand()-1)%n+1;
	y=(rand()-1)%n+1;
	for(int i=1;i<=10*n;i++){//初始化树
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		vis[x][y]=1;
		a[x][y]='W';
	}
	for(int i=1;i<=2*n;i++){//初始化铁
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		vis[x][y]=1;
		a[x][y]='R';
	}
	for(int i=1;i<=Firenum;i++){//初始化地狱中火焰
		while(hellvis[x][y]){
			x=(rand()-1)%helln+1;
			y=(rand()-1)%helln+1;
		}
		hellvis[x][y]=1;
		hell[x][y]='F';
	}
	for(int i=1;i<=Crystalnum;i++){//初始化地狱中水晶
		while(hellvis[x][y]){
			x=(rand()-1)%helln+1;
			y=(rand()-1)%helln+1;
		}
		hellvis[x][y]=1;
		hell[x][y]='T';
	}
	for(int i=1;i<=Ruinsnum;i++){//初始化地狱中遗迹
		while(hellvis[x][y]){
			x=(rand()-1)%helln+1;
			y=(rand()-1)%helln+1;
		}
		hellvis[x][y]=1;
		hell[x][y]='@';
		for(int j=x-5;j<=x+5;j++){
			for(int l=y-5;l<=y+5;l++){
				if(hellvis[j][l])continue;
				int qp=rand()%6;
				hell[j][l]=Ruinsthings[qp];
			}
		}
	}
	for(int i=1;i<=Boomnum;i++){//初始化炸弹
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		vis[x][y]=1;
		a[x][y]='X';
	}
	for(int i=1;i<=Unum;i++){//初始化磁铁
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		vis[x][y]=1;
		a[x][y]='U';
	}
	for(int i=1;i<=Housenum;i++){//初始化房子
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		vis[x][y]=1;
		a[x][y]='H';
	}
	for(int i=1;i<=Cavenum;i++){//初始化洞穴
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		caveid[x][y]=i;
		vis[x][y]=1;
		a[x][y]='C';
	}
	for(int i=1;i<=Helldoornum;i++){//初始化地狱传送门
		while(vis[x][y]||(x==n/2&&y==n/2)){
			x=(rand()-1)%n+1;
			y=(rand()-1)%n+1;
		}
		vis[x][y]=1;
		a[x][y]='M';
	}
	for(int id=1;id<=Cavenum;id++){//初始化洞穴内部
		for(int i=1;i<=100;i++){
			for(int j=1;j<=100;j++){
				cave[id][i][j]='.';
			}
		}
		for(int i=1;i<=100;i++)cave[id][i][100]=cave[id][100][i]=cave[id][1][i]=cave[id][i][1]='R';
		for(int i=1;i<=CaveSteelnum;i++){//初始化洞穴铁
			while(CaveSteel[id][x][y]||(x==50&&y==50)||x<2||y<2){
				x=(rand()-1)%99+1;
				y=(rand()-1)%99+1;
			}
			CaveSteel[id][x][y]=1;
			cave[id][x][y]='S';
		}
		for(int i=1;i<=CaveRocknum;i++){//初始化洞穴石头
			while(CaveRock[id][x][y]||(x==50&&y==50)||x<2||y<2){
				x=(rand()-1)%99+1;
				y=(rand()-1)%99+1;
			}
			CaveRock[id][x][y]=1;
			cave[id][x][y]='R';
		}
	}
	x=n/2,y=n/2;
	a[x][y]='O';
	while(blood>0){
		if(dayornight)system("color 0F");
		else system("color 07");
		if(day>=daytime){
			day=0;
			if(dayornight==0)nosleep++;
			dayornight=1-dayornight;
			if(dayornight)sizes=5;
			else sizes=3;
		}
		if(nosleep>=3){
			Dream();
			if(blood<=0)break;
		}
		init();
		for(int i=max(1,x-sizes);i<=min(n,x+sizes);i++){
			for(int j=max(1,y-sizes);j<=min(n,y+sizes);j++){
				cout<<a[i][j];
			}
			cout<<'\n';
		}
		char op;
		op=getch();
		if(op=='w'){
			way=0;
			move();
		}
		else if(op=='d'){
			way=1;
			move();
		}
		else if(op=='s'){
			way=2;
			move();
		}
		else if(op=='a'){
			way=3;
			move();
		}
		else if(op=='k'){
			int xx=x+dx[way];
			int yy=y+dy[way];
			if(a[xx][yy]=='W')a[xx][yy]='w',day++;
			if(a[xx][yy]=='S'&&breaklevel>1)a[xx][yy]='s',day++;
			if(a[xx][yy]=='R'&&breaklevel>0)a[xx][yy]='r',day++;
			if(a[xx][yy]=='H'&&breaklevel>3)BreakHouse(xx,yy);
		}
		else if(op=='x'){
			if(!boom)continue;
			day++;
			XBoom();
		}
		else if(op=='u'){
			if(!u)continue;
			day++;
			Uattract();
		}
		else if(op=='S'){
			Synthesis();
		}
		else if(op=='D'){
			Disassemble();
		}
		else if(op=='v'){
			if(!fast)continue;
			usefast=!usefast;
		}
		else if(op=='e'){
			E();
		}
	}
}
